package org.openkanban.server.session;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Component;

/**
 * Utility to read specific data out of the HttpServletRequest
 */
@Component
public class SessionAttributeHelper {

    public final static String ATTR_NAME_USERID = "userId";

    public Long getUserId(HttpServletRequest request) {
	if (sessionExists(request)) {
	    return (Long) request.getSession().getAttribute(ATTR_NAME_USERID);
	}
	return null;
    }

    private boolean sessionExists(HttpServletRequest request) {
	return request != null && request.getSession() != null;
    }

}
